package com.songgj.redission.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis")
public class RedisOperationController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/setKey")
    public void setKey() {
        // 设置键值对
        redisTemplate.opsForValue().set("key", "value");

        // 获取值
        String value = (String) redisTemplate.opsForValue().get("key");

        System.out.println("从redis中读取值为: "+value);
    }
}
